<?php

/*
 * ************************************************* 
 * Created on :2012-5-3 21:42:23
 * Encoding   :UTF-8
 * Description:
 * 
 * @Author @lqs <soso2501@gmail.com>
 * @WAP_WEIBO (C)1996-2099 SINA Inc. 
 * ************************************************
 */

class ajax {

    function upload() {
        $result = array("error" => 0, "url" => "");

        $ext_arr = array(
            'image' => array('gif', 'jpg', 'jpeg', 'png', 'bmp'),
            'flash' => array('swf', 'flv'),
            'media' => array('swf', 'flv', 'mp3', 'wav', 'wma', 'wmv', 'mid', 'avi', 'mpg', 'asf', 'rm', 'rmvb'),
            'file' => array('doc', 'docx', 'xls', 'xlsx', 'ppt', 'htm', 'html', 'txt', 'zip', 'rar', 'gz', 'bz2'),
        );

        if (empty($_FILES)) {
            $result['error'] = 1;
        } else {
            $result['url'] = Photo::upload($_FILES['imgFile']['tmp_name'], "jpg");
        }
        die(json_encode($result));
    }

    function uploadimg() {
        $ext = array('gif', 'jpg', 'jpeg', 'png', 'bmp');
        $result = array("error" => 1, "url" => '');
        if (!empty($_FILES['imgFile'])) {
            if ($_FILES['imgFile']['error'] != 0) {
                $msg = "上传出错，代码为:{$_FILES['imgFile']['error']}";
            } else {
                $cext = pathinfo($_FILES['imgFile']['name'], PATHINFO_EXTENSION);
                if (!in_array(strtolower($cext), $ext)) {
                    $msg = "非法的文件类型";
                } else {
                    $result['error'] = 0;
                    $msg = Photo::upload($_FILES['imgFile']['tmp_name'], "jpg");
                }
            }
        }
        $result['url'] = $msg;
        var_dump($_REQUEST);
        if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'albumphoto' && $result['error'] == 0) {
            $thumb = Photo::genthumb($result['url']);
            Photo::addphoto("", $result['url'], $thumb, $_REQUEST['albumid']);
        }
        die(json_encode($result));
    }

}

/* End of file ajax */


